/**常量**/
var ConstantManage = {
	getEncryColumnType: {"01":"证件号","02":"手机号","03":"卡号","04":"户名","05":"地址","06":"卡有效期","07":"邮箱","08":"其它"},
	getProcessStatus: {0:"待处理",1:"处理中",2:"处理完成",9:"失效"},
    getExpiredStatus: {0:"生效",1:"过期"}
}
/**获取常量**/
var ConstantTranslation = {
	getExpiredStatus:function (type) {
        return ConstantManage.getExpiredStatus[type];
    }, 
    getProcessStatus:function (processStatus) {
        return ConstantManage.getProcessStatus[processStatus];
    }, 
    getEncryColumnType:function (encryColumnType) {
        return ConstantManage.getEncryColumnType[encryColumnType];
    }, 
}
/**格式化日期**/
function formatDate(value) {
    if (value == null || value == '') {
        return '';
    }
    var dt;
    if (value instanceof Date) {
        dt = value;
    } else {
        dt = new Date(value);
    }
    return dt.format("yyyy-MM-dd hh:mm:ss");
}

/**格式化日期yyyy-MM-dd**/
function formatDateYYMMdd(value) {
    if (value == null || value == '') {
        return '';
    }
    var dt;
    if (value instanceof Date) {
        dt = value;
    } else {
        dt = new Date(value);
    }
    return dt.format("yyyy-MM-dd");
}

function formatAmount(value){
//金额转换 分->元 保留2位小数 并每隔3位用逗号分开 1,234.56
  if(value!=''){
    var result = (value.toString()).indexOf(".");
    if(result != -1) {
    	var str = Number(value).toFixed(6);
    	var intSum = str.substring(0,str.indexOf(".")).replace( /\B(?=(?:\d{3})+$)/g, ',' );//取到整数部分
    	var dot = str.substring(str.length,str.indexOf(".")).replace(/0*$/, '' )//取到小数部分搜索
        var ret = intSum + dot;
    	return ret;
    } else {
    	var str = value + '.00';
    	var intSum = str.substring(0,str.indexOf(".")).replace( /\B(?=(?:\d{3})+$)/g, ',' );//取到整数部分
    	var dot = str.substring(str.length,str.indexOf("."))//取到小数部分搜索
        var ret = intSum + dot;
    	return ret;
     }
   }else{
	   return '0';
   }
}

jQuery.prototype.serializeObject=function(){
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

function runNian(_year) {
    if(_year%400 === 0 || (_year%4 === 0 && _year%100 !== 0) ) {
        return true;
    }
    else { return false; }
}
function yesterday(){
    var today=new Date();
    var y=today.getFullYear();
    var m=today.getMonth()+1;
    var d=today.getDate()-1;
    if(d==0){
    	switch(m) {
            case 1: d = 31,m=m-1; break;
            case 2:
                if(runNian(y)){
            		d = 29,m=m-1; 
            	}else { 
            		d = 28,m=m-1; 
            	}
                break;
            case 3: d = 31,m=m-1; break;
            case 4: d = 30,m=m-1; break;
            case 5: d = 31,m=m-1; break;
            case 6: d = 30,m=m-1; break;
            case 7: d = 31,m=m-1; break;
            case 8: d = 31,m=m-1; break;
            case 9: d = 30,m=m-1; break;
            case 10: d = 31,m=m-1; break;
            case 11: d = 30,m=m-1; break;
            case 12: d = 31,m=m-1; break;
    	}
    }else{
    	 d= d<10?"0"+d:d;
    }
    if(m==0){
    	m=12;
    	y=y-1;
    }
    m= m<10?"0"+m:m;    
    return y+""+m+""+d; 
}

function yesterdayTime(){
    var today=new Date();
    var y=today.getFullYear();
    var m=today.getMonth()+1;
    var d=today.getDate()-1;
    var hh=today.getHours();
    var mm=today.getMinutes();
    var ss=today.getSeconds();
    if(d==0){
    	switch(m) {
            case 1: d = 31,m=m-1; break;
            case 2:
                if(runNian(y)){
                		d = 28,m=m-1; 
                	}else { 
                		d = 28,m=m-1; 
                	}
                break;
            case 3: d = 31,m=m-1; break;
            case 4: d = 30,m=m-1; break;
            case 5: d = 31,m=m-1; break;
            case 6: d = 30,m=m-1; break;
            case 7: d = 31,m=m-1; break;
            case 8: d = 31,m=m-1; break;
            case 9: d = 30,m=m-1; break;
            case 10: d = 31,m=m-1; break;
            case 11: d = 30,m=m-1; break;
            case 12: d = 31,m=m-1; break;
    	}
    }else{
    	 d= d<10?"0"+d:d;
    }
    if(m==0){
    	m=12;
    	y=y-1;
    }
    m= m<10?"0"+m:m;    
    hh = hh < 10 ? "0" + hh:hh;
    mm = mm < 10 ? "0" +  mm:mm;
    ss = ss < 10 ? "0" + ss:ss;
    return y+"-"+m+"-"+d+" "+hh+":"+mm+":"+ss; 
}
